const http2 = require('http2')

const reqBody = JSON.stringify({'name': 'ikejcwang'})
const client = http2.connect('http://127.0.0.1:8080');
const req = client.request({
    ':method': 'POST',
    ':path': '/hello',
    'content-type': 'application/json',
    'content-length': Buffer.byteLength(reqBody),
});

let resBody = [];
req.on('response', (headers, flags) => {
    console.dir(headers)
});
req.on('data', chunk => {
    resBody.push(chunk);
});
req.on('end', () => {
    console.log("resBody: " + resBody.toString())

    // client需要主动关闭，否则一直是连接状态
    // client.close()
});

req.end(reqBody)
